export default (await import('vue')).defineComponent({
data() {
return {
query: {
//左上角查询input
name: "",
},
//地图相关参数 START
Marker: null,
map: null,
//地图相关参数 END
options: [],
fatherAgenciesOptionData: [],
fatherCompanyIdData: [],
superAdministratorIdData: [],
authenticationStatusData: [
{ name: '未认证', id: '0' },
{ name: '已认证', id: '1' },
],
updateStaffId: 0,
dialogFormVisible: false,
formLabelWidth: "120px",
reinsertForm: {
shortName: '',
superAdministratorId: '',
type: '',
fatherCompanyId: '',
criCode: '',
contactName: '',
telephoneNumber: '',
authenticationStatus: '',
criLng: '',
criLat: '',
},
insertRules: {
phoneNumber: [
{
required: true,
message: "手机号不能为空",
trigger: "blur",
},
],
name: [
{
required: true,
message: "设备名称不能为空",
trigger: "blur",
},
],
},
operateType: 'insert',
genderListData: [
{ id: '0', name: "女" }, { id: '1', name: "男" }
],
fatherAgenciesOptionData: [],
typeOptionData: [],
agencyQuery: {
name: "",
},
superAdminQuery: {
userAccount: "",
userName: ""
},
userQuery: {
userAccount: "",
userName: ""
},
insertUserQuery: {
userAccount: "",
userName: "",
agencyDepartmentId: "",
agencyPostId: "",
},
reinsertForm: {
confirmType: 'insert',
},
breadcrumbsData: [],
agencyData: [],
userData: [],
superAdminUserData: [],
insertUserData: [],
depmentManageData: [],
agencyPostListData: [],
agencyPostDisabled: true,
multipleSelection: [],
pageNum: 0,
pageSize: 10,
totalSize: 0,
};
},

activated() {
//查询下级机构
// this.getAgencyList();
// 查询楼宇列表
this.queryAddedStaffList();
this.getAgencyInfo(this.$route.query.id);
this.operateType = 'binding';
this.querysuperAdminUserList();

//刚进入页面加载
this.getFatherAgenciesOptionData("");
//面包屑
this.getBreadcrumbsData();
this.queryInsertUserList();

},
async mounted() {
//初始化选项数据
this.getAgencyTypeOptionData();


},
methods: {
// 打开新增楼宇页面
openForm() {
this.$router.push({
path: '/room/roomInsert',
query: {
operateType: 'insert',
id: this.$route.query.id
}
});
},
//打开楼宇详情
openDetailPage(row) {
var id = row.id;
this.$router.push({
path: '/room/roomDetail',
query: { id: id }
}, () => {
// location.reload();//刷新页面
});
},
//修改房间信息
echoValueForUpdate(row) {
this.$router.push({
path: '/room/roomInsert',
query: {
id: row.id,
operateType: 'update'
}
});
},
//删除房间
deleteAgencyById(row) {
console.log('删除房间');
this.$confirm('确定要删除该房间信息吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
let res = await DelRoom(row.id);
console.log(res, '删除楼宇');
if (res.data.code == 200) {
this.$message({
message: "删除成功",
type: "success"
});
} else {
this.$message({
message: res.data.message,
type: "warning"
});
}
this.queryAddedStaffList();

}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
},
// 定位详细坐标
positioning(val) {

// 设置中心点
this.map.setCenter([val.lon, val.lat]);

// 设置高度
this.map.setZoom([15]);

// 如果之前添加个散点那么就去除
if (this.Marker != null) {
this.Marker.remove();
console.log('删除marker', this.Marker);
}

// 添加散点
this.Marker = new AMap.Marker({
position: new AMap.LngLat(val.lon, val.lat),
title: val.title,
anchor: 'bottom-center',
});
this.map.add(this.Marker);
},
// ShowMap(val) {
//   let that = this
//   this.$nextTick(() => {
//     // 如果地图为空 则初始化地图
//     if (this.map == null) {
//       AMapLoader.load({
//         key: "b59ffa4664995330f554d4aedc02b03c", // 申请好的Web端开发者Key，首次调用 load 时必填
//         version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
//         plugins: [], // 需要使用的的插件列表，如比例尺'AMap.Scale'等
//       })
//         .then((AMap) => {
//           that.map = new AMap.Map("container", {
//             // 设置地图容器id
//             // viewMode: "3D", // 是否为3D地图模式
//             // zoom: 11, // 初始化地图级别
//             // center: [116.397428, 39.90923], // 初始化地图中心点位置
//           });
//           that.positioning(val)
//         })
//         .catch((e) => {
//           console.log(e);
//         });
//     } else {
//       this.positioning(val)
//     }
//   })
// },
handleChange() {
},


/**
*  上一页
*/
goBack() {
this.$router.back(-1);
},

/**
* 获取上级机关列表
*/
async getFatherAgenciesOptionData(name) {
// 上级机构信息
let ShangJiJiGouList = await getShangJiJiGouList();
this.fatherCompanyIdData = [];
console.log(ShangJiJiGouList, '上级机构列表');
ShangJiJiGouList.forEach(el => {
this.fatherCompanyIdData.push({
name: el.shortName,
type: el.id
});
});
this.fatherCompanyIdData.unshift({
name: '无',
type: 0
});
// 机构type类型获取
this.fatherAgenciesOptionData = [
{ name: "物业公司", type: '1' },
{ name: "其他机构", type: '2' }
];
// 获取管理员信息
this.superAdministratorIdData = [
{ name: '超级管理员', type: 0 },
{ name: '普通管理员', type: 1 }
];
},


/**
* 获取类型字典数据
*/
getAgencyTypeOptionData() {
getDictionaryList("agency_type").then((res) => {
this.typeOptionData = res.data;
});
},



// 获取机构详情
getAgencyInfo(id) {
getInDetail(id).then((res) => {
console.log(res, '楼宇详情');
this.reinsertForm = res;
this.reinsertForm.createTime = this.reinsertForm.createTime == null ? this.reinsertForm.createTime : this.reinsertForm.createTime.slice(0, 10);
this.reinsertForm.updateTime = this.reinsertForm.updateTime == null ? this.reinsertForm.updateTime : this.reinsertForm.updateTime.slice(0, 10);
});
},



bindingUserAccount(row) {
console.log(row);
var userId = row.id;
var instId = this.$route.query.id;
var name = row.name;
var account = row.account;
bindingAU(instId, userId).then((res) => {
if (res.code == 200) {
this.$message({
message: '绑定成功',
type: 'success'
});
this.$nextTick(() => {
// this.reinsertForm.superAdministratorId = name;
this.getAgencyInfo(instId);
});

} else {
this.$message({
message: res.message,
type: "warning",
});
}
});
},
unbindingUserAccount(row) {
var userId = row.id;
var instId = this.$route.query.id;
unbindingAU(instId, userId).then((res) => {
if (res.code == 200) {
this.$message({
message: '解绑成功',
type: 'success'
});
this.$nextTick(() => {
// this.reinsertForm.superAdministratorName = "无";
this.getAgencyInfo(instId);
});

} else {
this.$message({
message: res.message,
type: "warning",
});
}
});
},

//按条件查询菜单列表
getAgencyList() {
getAgencyList(
this.agencyQuery.name,
this.$route.query.id,
this.pageNum,
this.pageSize
).then((res) => {
console.log(res, '下级机构');
this.agencyData = [];
res.list.forEach(el => {
this.agencyData.push(el);
});
this.pageNum = res.pageNum;
this.pageSize = res.pageSize;
this.totalSize = res.total;
});
},

//打开添加员工弹框
openInsertDialogForm() {
this.dialogFormVisible = true;
this.reinsertForm.confirmType = 'insert';
//查询待添加的用户列表
this.queryInsertUserList();
this.getDepartmentHierarchically();
this.insertUserQuery.agencyDepartmentId = "";
this.insertUserQuery.agencyPostId = "";
},
//打开员工修改弹框
openEditDialogForm(row) {

this.updateStaffId = row.id;
this.dialogFormVisible = true;

this.reinsertForm.confirmType = 'update';
//查询待修改的用户列表
this.getDepartmentHierarchically();
this.getAgencyStaffDetail(this.updateStaffId);
this.getPostListByDepId();
this.insertUserQuery.agencyDepartmentId = "";
this.insertUserQuery.agencyPostId = "";
},
//按条件查询账号列表
queryAddedStaffList() {
getroomList({ buildingId: this.$route.query.id }).then((res) => {
console.log(res, '房间列表');
this.userData = res.list;
// this.pageNum = res.pageNum;
// this.pageSize = res.pageSize;
// this.totalSize = res.total;
});
},
//按条件查询账号列表
querysuperAdminUserList() {
var status = '1';
getUserList(
this.superAdminQuery.userAccount,
this.superAdminQuery.userName,
status,
this.pageNum,
this.pageSize
).then((res) => {
this.superAdminUserData = res.list;
this.pageNum = res.pageNum;
this.pageSize = res.pageSize;
this.totalSize = res.total;
});
},
//按条件查询账号列表
queryInsertUserList() {
var status = '1';
getUserList(
this.insertUserQuery.userAccount,
this.insertUserQuery.userName,
status,
this.pageNum,
this.pageSize
).then((res) => {
console.log(res, 'qwdqqwd');
this.insertUserData = res.list;
this.pageNum = res.pageNum;
this.pageSize = res.pageSize;
this.totalSize = res.total;
});
},
//查询部门
getDepartmentHierarchically() {
var instId = this.$route.query.id;
getDepartmentHierarchically(
2
).then((res) => {
console.log(res, '部门列表');
this.depmentManageData = res.data;
});
},
//查询岗位
getPostListByDepId() {
getPostListByDepId(
this.insertUserQuery.agencyDepartmentId[this.insertUserQuery.agencyDepartmentId.length - 1]
).then((res) => {
this.agencyPostListData = res.data;
});
},
//部门选择变动事件
departmentChangeEvent() {
if (this.insertUserQuery.agencyDepartmentId.length > 0) {
this.agencyPostDisabled = false;
} else {
this.agencyPostDisabled = true;
}
this.getPostListByDepId();


},
handleSelectionChange(val) {
this.multipleSelection = val;
},
//添加员工
addStaff() {
var agencyId = this.$route.query.id;
var depIds = this.insertUserQuery.agencyDepartmentId;
var postIds = this.insertUserQuery.agencyPostId;
if (this.multipleSelection.length == 0) {
this.$message({
message: '请先选择至少一个账号进行绑定',
type: "warning",
});
return;
}
if (depIds == "") {
this.$message({
message: '请选择部门',
type: "warning",
});
return;
}
if (postIds == "") {
this.$message({
message: '请选择岗位',
type: "warning",
});
return;
}


var tempUserId = "";
if (this.multipleSelection) {
this.multipleSelection.forEach(row => {
tempUserId = tempUserId + "," + row.id;
});
var userId = tempUserId.substring(1);



addStaff(agencyId, userId, depIds, postIds).then((res) => {
if (res.code == 200) {
this.$message({
message: '添加员工成功',
type: 'success'
});
this.dialogFormVisible = false;
this.queryAddedStaffList();

} else {
this.$message({
message: res.message,
type: "warning",
});
}
});
}
},
//删除员工
deleteStaffById(row) {
var staffId = row.id;
this.$confirm("确认删除该员工吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {

deleteStaff(staffId).then((res) => {
if (res.code == 200) {
this.$message({
message: '删除成功',
type: 'success'
});
this.queryAddedStaffList();
} else {
this.$message({
message: res.message,
type: "warning",
});
}
});

}).catch(() => {
this.$message({
type: "info",
message: "已取消删除",
});
return;
});

},

//查询面包屑数据
getBreadcrumbsData() {
console.log(this, '??????');
var agencyId = this.$route.query.id;

getBreadcrumbs(agencyId).then((res) => {
console.log(res, '面包屑数据');
let arr = [];
res.forEach(el => {
if (el != null) {
arr.push(el);
}
});
this.breadcrumbsData = arr;
});

},

tiktak(id) {
this.$router.replace({
path: '/residential/reDetail',
query: { id: id }
}, () => {
location.reload(); //刷新页面
});

},

getAgencyStaffDetail(staffId) {
getAgencyStaffDetail(staffId).then((res) => {
if (res.code == 200) {
var agencyStaff = res.data;
this.insertUserQuery.agencyDepartmentId = eval('([' + agencyStaff.departmentIds + '])');
this.insertUserQuery.agencyPostId = eval('([' + agencyStaff.postIds + '])');
var selection = eval('([' + agencyStaff.userId + '])');
this.getPostListByDepId();
this.agencyPostDisabled = false;
this.insertUserData.forEach((item) => {
selection.forEach((staff) => {
if (item.id == staff) {
this.$nextTick(() => {
//设置当前用户高亮
this.$refs.addStaffTable.clearSelection();
this.$refs.addStaffTable.toggleRowSelection(item, true);
});
}
});
});


} else {
this.$message({
message: res.message,
type: "warning",
});
}
});

},

updateStaff() {
var agencyId = this.$route.query.id;
var depIds = this.insertUserQuery.agencyDepartmentId;
var postIds = this.insertUserQuery.agencyPostId;

if (this.multipleSelection.length == 0) {
this.$message({
message: '请先选择至少一个账号进行绑定',
type: "warning",
});
return;
}
if (depIds == "") {
this.$message({
message: '请选择部门',
type: "warning",
});
return;
}
if (postIds == "") {
this.$message({
message: '请选择岗位',
type: "warning",
});
return;
}


var tempUserId = "";
if (this.multipleSelection) {


if (this.multipleSelection.length > 1) {
this.$message({
message: '只能选一个账号进行修改',
type: "warning",
});
return;
}


this.multipleSelection.forEach(row => {
tempUserId = tempUserId + "," + row.id;
});
var userId = tempUserId.substring(1);



updateStaff(this.updateStaffId, agencyId, userId, depIds, postIds).then((res) => {
if (res.code == 200) {
this.$message({
message: '修改成功',
type: 'success'
});
this.dialogFormVisible = false;
this.$nextTick(() => {
this.queryAddedStaffList();
});

} else {
this.$message({
message: res.message,
type: "warning",
});
}
});
}
},
}
});
